package com.minelx.datamicroscope.core.condition;

import com.minelx.datamicroscope.core.values.CommonField;

import java.util.Collection;
import java.util.List;

import static java.util.stream.Collectors.joining;
import static java.util.stream.Collectors.toList;

public class AndCondition implements Condition {
	private final List<Condition> conditions;

	public AndCondition(List<Condition> conditions) {
		this.conditions = conditions;
	}

	@Override
	public String sqlText() {
		return conditions.stream().map(Condition::sqlText).collect(joining(" AND "));
	}

	@Override
	public List<CommonField> containedFields() {
		return conditions.stream()
				.map(Condition::containedFields)
				.flatMap(Collection::stream)
				.collect(toList());
	}

	public List<Condition> getConditions() {
		return conditions;
	}
}
